﻿using Customer.API.Applcation.Command.ProcurementCommand;
using Customer.Infrstructre.ProcurementManager;
using MediatR;

namespace Customer.API.Applcation.CommandHandlers.ProcurementCommandHandler
{
    public class ProcurementDelCommandHandler : IRequestHandler<ProcurementDelCommand, int>
    {

        IProcureProductRepository rRep;

        public ProcurementDelCommandHandler(IProcureProductRepository rRep)
        {
            this.rRep = rRep;
        }

        public async Task<int> Handle(ProcurementDelCommand request, CancellationToken cancellationToken)
        {
            var list = (await rRep.GetAllAsync()).Where(c => request.ProcureProductId.Contains(c.ProcureProductId)).ToList();

            foreach (var item in list)
            {
                item.IsDel = true;
                item.DelName = request.DelName;
                item.DelTime = DateTime.Now;
                await rRep.Update(item);
            }
            return 1;
        }
    }
}
